class Solution {
public:
    set<int> s;
    int longestConsecutive(vector<int>& nums) {
        if (!nums.size()) return 0;
        for (auto& x : nums) s.insert(x);
        vector<int> temp;
        for (auto& x : s) temp.push_back(x);
        int ans = 1;
        int num = 1;
        for (int i = 1; i < temp.size(); i++)
        {
            if (temp[i - 1] == temp[i] - 1) num += 1;
            else num = 1;
            ans = max(ans, num);
        }
        return ans;
    }
};